package demo.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import generated.BIBLEBOOK;
import generated.CHAPTER;

public class Book {

	public static Book createFromZefania(BIBLEBOOK bibleBook) {
		return new Book(bibleBook);
	}

	public String name;
	public String id;
	public int bookNumber;
	public List<Chapter> chapters = new ArrayList<Chapter>();
	public static Map<Integer, String> BOOK_KEYS = new HashMap<Integer, String>(
			66);

	static {
		BOOK_KEYS.put(1, "gen");
		BOOK_KEYS.put(2, "exod");
		BOOK_KEYS.put(3, "lev");
		BOOK_KEYS.put(4, "num");
		BOOK_KEYS.put(5, "deut");
		BOOK_KEYS.put(6, "josh");
		BOOK_KEYS.put(7, "judg");
		BOOK_KEYS.put(8, "ruth");
		BOOK_KEYS.put(9, "1sam");
		BOOK_KEYS.put(10, "2sam");
		BOOK_KEYS.put(11, "1kgs");
		BOOK_KEYS.put(12, "2kgs");
		BOOK_KEYS.put(13, "1chr");
		BOOK_KEYS.put(14, "2chr");
		BOOK_KEYS.put(15, "ezra");
		BOOK_KEYS.put(16, "neh");
		BOOK_KEYS.put(17, "esth");
		BOOK_KEYS.put(18, "job");
		BOOK_KEYS.put(19, "ps");
		BOOK_KEYS.put(20, "prov");
		BOOK_KEYS.put(21, "eccl");
		BOOK_KEYS.put(22, "song");
		BOOK_KEYS.put(23, "isa");
		BOOK_KEYS.put(24, "jer");
		BOOK_KEYS.put(25, "lam");
		BOOK_KEYS.put(26, "ezek");
		BOOK_KEYS.put(27, "dan");
		BOOK_KEYS.put(28, "hos");
		BOOK_KEYS.put(29, "joel");
		BOOK_KEYS.put(30, "amos");
		BOOK_KEYS.put(31, "obad");
		BOOK_KEYS.put(32, "jonah");
		BOOK_KEYS.put(33, "mic");
		BOOK_KEYS.put(34, "nah");
		BOOK_KEYS.put(35, "hab");
		BOOK_KEYS.put(36, "zeph");
		BOOK_KEYS.put(37, "hag");
		BOOK_KEYS.put(38, "zech");
		BOOK_KEYS.put(39, "mal");
		BOOK_KEYS.put(40, "matt");
		BOOK_KEYS.put(41, "mark");
		BOOK_KEYS.put(42, "luke");
		BOOK_KEYS.put(43, "john");
		BOOK_KEYS.put(44, "acts");
		BOOK_KEYS.put(45, "rom");
		BOOK_KEYS.put(46, "1cor");
		BOOK_KEYS.put(47, "2cor");
		BOOK_KEYS.put(48, "gal");
		BOOK_KEYS.put(49, "eph");
		BOOK_KEYS.put(50, "phil");
		BOOK_KEYS.put(51, "col");
		BOOK_KEYS.put(52, "1thess");
		BOOK_KEYS.put(53, "2thess");
		BOOK_KEYS.put(54, "1tim");
		BOOK_KEYS.put(55, "2tim");
		BOOK_KEYS.put(56, "titus");
		BOOK_KEYS.put(57, "phlm");
		BOOK_KEYS.put(58, "heb");
		BOOK_KEYS.put(59, "jas");
		BOOK_KEYS.put(60, "1pet");
		BOOK_KEYS.put(61, "2pet");
		BOOK_KEYS.put(62, "1john");
		BOOK_KEYS.put(63, "2john");
		BOOK_KEYS.put(64, "3john");
		BOOK_KEYS.put(65, "jude");
		BOOK_KEYS.put(66, "rev");
	}

	private Book(BIBLEBOOK bibleBook) {
		this.name = bibleBook.getBname();
		this.id = BOOK_KEYS.get(bibleBook.getBnumber().intValue());
		this.bookNumber = bibleBook.getBnumber().intValue();
		assert this.id != null;

		if (this.name == null) {
			try {
				this.name = ("" + this.id.charAt(0)).toUpperCase()
						+ this.id.substring(1);
			} catch (Exception e) {
				this.name = this.id;
			}
		}
		for (Object element : bibleBook.getPROLOGOrCHAPTER()) {
			if (element instanceof CHAPTER) {
				CHAPTER chapter = (CHAPTER) element;

				chapters.add(Chapter.createFromZefania(chapter));
			}
		}
	}

}
